package be.ac.ua.customer.gui;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.util.Vector;

import javax.swing.ImageIcon;

import distrcomp.Address;

import net.jini.core.lease.LeaseDeniedException;
import net.jini.core.transaction.TransactionException;

import be.ac.ua.codebase.*;
import be.ac.ua.customer.CustomerImplementation;


public class Gui extends javax.swing.JFrame implements GuiInterface{
	private Captcha fCaptcha;
	private CustomerImplementation fCustomer;

	public Gui() throws IOException {
		initComponents();
		refreshCaptcha();
		addNotification("IMPORTANT: register first!");
	}

	private void refreshCaptcha() throws MalformedURLException {
		fCaptcha = new Captcha();
		fCaptchaImage.setIcon(new ImageIcon(new URL(fCaptcha.getImageUrl())));
	}

	private void addNotification(String notification) {
		fTxtNotifications.setText(fTxtNotifications.getText() + "\n" + notification);
	}

	private void fBtnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnSearchActionPerformed
		try {
			Vector<Product> searchResult = fCustomer.getStoreConnector().search(fTxtNameSearch.getText());
			if (searchResult.isEmpty())
				addNotification("No product found.");
			for (int i = 0; i < searchResult.size(); i++) {
				addNotification("Found product with name: " + searchResult.get(i).getName());
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}//GEN-LAST:event_fBtnSearchActionPerformed

	private void fJoinAuctionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fJoinAuctionActionPerformed
		try {
			Vector<Product> searchResult = fCustomer.getStoreConnector().search(fTxtJoinAuction.getText());

			//Export customer1 and get a proxy
			CustomerInterface customer1Proxy = fCustomer.export();

			//Join a bidding
			if(searchResult.size() > 0) {
				fCustomer.joinBidding(searchResult.get(0).getID());
				addNotification("Auction for product " + searchResult.get(0).getName() + " joined.");
			} else {
				addNotification("Auction not found.");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}//GEN-LAST:event_fJoinAuctionActionPerformed


	private void fBtnCreditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnCreditActionPerformed
		try {
			fCustomer.getBank().credit(fCustomer.getBankAccountID(), Integer.parseInt(fTxtCredit.getText()));
			addNotification("Credit: " + Integer.parseInt(fTxtCredit.getText()));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}//GEN-LAST:event_fBtnCreditActionPerformed

	private void fBtnDebitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnDebitActionPerformed
		try {
			fCustomer.getBank().debit(fCustomer.getBankAccountID(), Integer.parseInt(fTxtDebit.getText()));
			addNotification("Debit: " + Integer.parseInt(fTxtDebit.getText()));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}//GEN-LAST:event_fBtnDebitActionPerformed

	private void fBtnAddProductActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnAddProductActionPerformed
		try {
			Product product = new Product(fTxtAddName.getText());
			Long duration = Long.parseLong(fTxtDuration.getText()) * 1000;
			Double minAmount = Double.parseDouble(fTxtMinAmount.getText());
			Double maxAmount = Double.parseDouble(fTxtMaxAmount.getText());
			String auctionType = "be.ac.ua.codebase.VickreyAuction";
			
			if (fRbtnVickrey.isSelected()) {
				auctionType = "be.ac.ua.codebase.VickreyAuction";
			} else if (fRbtnEnglish.isSelected()) {
				auctionType = "be.ac.ua.codebase.EnglishAuction";
			} else if (fRbtnDutch.isSelected()) {
				auctionType = "be.ac.ua.codebase.DutchAuction";
			}
			
			fCustomer.offerProduct(product, duration, minAmount, maxAmount, auctionType);
			addNotification("Added product with name: " + fTxtAddName.getText());
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (LeaseDeniedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransactionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}//GEN-LAST:event_fBtnAddProductActionPerformed

	private void fBtnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnSubmitActionPerformed
		addNotification("Registering...");

		try {
			Address address = new Address(txtStreet.getText(),txtNumber.getText(), fPostcode.getText(), txtCity.getText(), txtCountry.getText());
			fCustomer = new CustomerImplementation(fFirstname.getText(), fLastname.getText(), address);
			
			fCustomer.setGui(this);

			addNotification("New account with name: " + fFirstname.getText() + " " + fLastname.getText());
			Thread.sleep(1000);
			fCustomer.registerWithBank();
			addNotification("Bank account created with id: " + fCustomer.getBankAccountID().toString());
			CustomerInterface customer1Proxy = fCustomer.export();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		try {
			fCustomer.getBank().credit(fCustomer.getBankAccountID(), Integer.parseInt(fInitialcredit.getText()));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		addNotification("Initial credit on bank account: " +  Integer.parseInt(fInitialcredit.getText()));

		fTabs.setEnabled(true);

	}//GEN-LAST:event_fBtnSubmitActionPerformed

	private void fBtnPlaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnPlaceActionPerformed
		try {
			boolean result = fCaptcha.getResult(fTxtCaptcha.getText());
			if (result) {
				Vector<Product> searchResult = fCustomer.getStoreConnector().search(fTxtJoinAuction.getText());

				//Export customer1 and get a proxy
				CustomerInterface customer1Proxy = fCustomer.export();

				if(searchResult.size() > 0) {
					fCustomer.placeBidding(searchResult.get(0).getID(), Integer.parseInt(fTxtBid.getText()));
					addNotification("Bid on object with name " + searchResult.get(0).getName() + " placed: " + fTxtBid.getText());
				} else {
					addNotification("Auction not found.");
				}
			} else {
				addNotification("Wrong captcha");
			}

			refreshCaptcha();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}//GEN-LAST:event_fBtnPlaceActionPerformed

	private void fTxtCaptchaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fTxtCaptchaActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_fTxtCaptchaActionPerformed

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        fTxtNotifications = new javax.swing.JTextArea();
        fLblNotifications = new javax.swing.JLabel();
        fTabs = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        fLblNameSearch = new javax.swing.JLabel();
        fTxtNameSearch = new javax.swing.JTextField();
        fBtnSearch = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        fLblNameProductAdd = new javax.swing.JLabel();
        fTxtAddName = new javax.swing.JTextField();
        fBtnAddProduct = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        fTxtDuration = new javax.swing.JTextField();
        fTxtMinAmount = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        fTxtMaxAmount = new javax.swing.JTextField();
        fRbtnDutch = new javax.swing.JRadioButton();
        fRbtnEnglish = new javax.swing.JRadioButton();
        fRbtnVickrey = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        fLblBid = new javax.swing.JLabel();
        fTxtBid = new javax.swing.JTextField();
        fBtnPlace = new javax.swing.JButton();
        fCaptchaImage = new javax.swing.JLabel();
        fTxtCaptcha = new javax.swing.JTextField();
        fCaptchaLabel = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        fTxtJoinAuction = new javax.swing.JTextField();
        fJoinAuction = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        fTxtCredit = new javax.swing.JTextField();
        fTxtDebit = new javax.swing.JTextField();
        fBtnDebit = new javax.swing.JButton();
        fBtnCredit = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        fFirstname = new javax.swing.JTextField();
        fLastname = new javax.swing.JTextField();
        fPostcode = new javax.swing.JTextField();
        fBtnSubmit = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        fInitialcredit = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtNumber = new javax.swing.JTextField();
        txtCity = new javax.swing.JTextField();
        txtCountry = new javax.swing.JTextField();
        txtStreet = new javax.swing.JTextField();
        fBtnGetNotifications = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        fTxtNotifications.setColumns(20);
        fTxtNotifications.setEditable(false);
        fTxtNotifications.setRows(5);
        fTxtNotifications.setEnabled(false);
        jScrollPane1.setViewportView(fTxtNotifications);

        fLblNotifications.setText("Notifications:");

        fTabs.setEnabled(false);

        fLblNameSearch.setText("Name:");

        fBtnSearch.setText("Search");
        fBtnSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnSearchActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(fTxtNameSearch)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(fLblNameSearch)
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                .add(0, 327, Short.MAX_VALUE)
                .add(fBtnSearch))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(fLblNameSearch)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtNameSearch, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fBtnSearch)
                .addContainerGap(229, Short.MAX_VALUE))
        );

        fTabs.addTab("Search", jPanel1);

        fLblNameProductAdd.setText("Name:");

        fBtnAddProduct.setText("Add");
        fBtnAddProduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnAddProductActionPerformed(evt);
            }
        });

        jLabel13.setText("Duration:");

        jLabel15.setText("Minimum Amount:");

        jLabel16.setText("Auctiontype:");

        fTxtMinAmount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fTxtMinAmountActionPerformed(evt);
            }
        });

        jLabel17.setText("Maximum Amount:");

        buttonGroup1.add(fRbtnDutch);
        fRbtnDutch.setText("Dutch");

        buttonGroup1.add(fRbtnEnglish);
        fRbtnEnglish.setText("English");

        buttonGroup1.add(fRbtnVickrey);
        fRbtnVickrey.setText("Vickrey");

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(fTxtAddName)
                                    .add(fTxtDuration)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, fTxtMinAmount, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 394, Short.MAX_VALUE)
                                    .add(jPanel2Layout.createSequentialGroup()
                                        .add(jLabel17)
                                        .add(0, 0, Short.MAX_VALUE)))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel14))
                            .add(fLblNameProductAdd)
                            .add(jLabel13)
                            .add(jLabel15)
                            .add(jLabel16)
                            .add(fTxtMaxAmount))
                        .addContainerGap())
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(fRbtnVickrey)
                            .add(fRbtnDutch))
                        .add(18, 18, 18)
                        .add(fRbtnEnglish)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(fBtnAddProduct)
                        .add(22, 22, 22))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(fLblNameProductAdd)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtAddName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtDuration, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel15)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(jLabel14)
                        .add(29, 29, 29))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(fTxtMinAmount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(7, 7, 7)
                        .add(jLabel17)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtMaxAmount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel16)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(22, 22, 22)
                        .add(fBtnAddProduct))
                    .add(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(fRbtnVickrey)
                            .add(fRbtnEnglish))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(fRbtnDutch)))
                .add(0, 21, Short.MAX_VALUE))
        );

        fTabs.addTab("Add Product", jPanel2);

        fLblBid.setText("Bid:");

        fBtnPlace.setText("Place");
        fBtnPlace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnPlaceActionPerformed(evt);
            }
        });

        fCaptchaImage.setIcon(new javax.swing.ImageIcon("/Users/niel/Desktop/captcha.gif")); // NOI18N

        fTxtCaptcha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fTxtCaptchaActionPerformed(evt);
            }
        });

        fCaptchaLabel.setText("Captcha:");

        jLabel8.setText("Join auction:");

        fTxtJoinAuction.setText("product name");

        fJoinAuction.setText("Join");
        fJoinAuction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fJoinAuctionActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, fTxtJoinAuction)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, fTxtCaptcha)
                    .add(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(fTxtBid)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, fBtnPlace)
                            .add(jPanel3Layout.createSequentialGroup()
                                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(fLblBid)
                                    .add(fCaptchaLabel)
                                    .add(jPanel3Layout.createSequentialGroup()
                                        .add(6, 6, 6)
                                        .add(fCaptchaImage))
                                    .add(jLabel8))
                                .add(0, 144, Short.MAX_VALUE))))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(fJoinAuction)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtJoinAuction, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fJoinAuction)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(fLblBid)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fTxtBid, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fCaptchaLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fCaptchaImage)
                .add(11, 11, 11)
                .add(fTxtCaptcha, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fBtnPlace)
                .addContainerGap())
        );

        fTabs.addTab("Bidding", jPanel3);

        jLabel6.setText("Credit:");

        jLabel7.setText("Debit:");

        fBtnDebit.setText("Debit");
        fBtnDebit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnDebitActionPerformed(evt);
            }
        });

        fBtnCredit.setText("Credit");
        fBtnCredit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnCreditActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(fTxtCredit))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(jLabel7)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel4Layout.createSequentialGroup()
                                .add(0, 268, Short.MAX_VALUE)
                                .add(fBtnCredit))
                            .add(fTxtDebit)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                        .add(0, 0, Short.MAX_VALUE)
                        .add(fBtnDebit)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(fTxtCredit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(fBtnCredit))
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(38, 38, 38)
                        .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(fTxtDebit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel7))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(fBtnDebit)
                .addContainerGap(185, Short.MAX_VALUE))
        );

        fTabs.addTab("Bank", jPanel4);

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 412, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 320, Short.MAX_VALUE)
        );

        fTabs.addTab("Start", jPanel5);

        fTabs.setSelectedComponent(jPanel5);

        jLabel1.setText("Register: ");

        jLabel2.setText("Firstname:");

        jLabel3.setText("Lastname:");

        jLabel4.setText("Post code:");

        fPostcode.setText("H1J2V8");

        fBtnSubmit.setText("Submit");
        fBtnSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnSubmitActionPerformed(evt);
            }
        });

        jLabel5.setText("Credit:");

        jLabel9.setText("Street:");

        jLabel10.setText("Number:");

        jLabel11.setText("City:");

        jLabel12.setText("Country:");

        txtNumber.setText("8001");

        txtCity.setText("Anjou");

        txtCountry.setText("CA");

        txtStreet.setText("Pauline Vanier");

        fBtnGetNotifications.setText("Get Notifications");
        fBtnGetNotifications.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fBtnGetNotificationsActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, fTabs, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 433, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(layout.createSequentialGroup()
                                        .add(jLabel5)
                                        .add(29, 29, 29)
                                        .add(fInitialcredit))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                        .add(jLabel4)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(fPostcode))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                        .add(jLabel3)
                                        .add(8, 8, 8)
                                        .add(fLastname))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                        .add(jLabel2)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(fFirstname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 128, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel10)
                                    .add(jLabel11)
                                    .add(jLabel12)
                                    .add(jLabel9)))
                            .add(layout.createSequentialGroup()
                                .add(fLblNotifications)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(fBtnGetNotifications)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(txtNumber)
                            .add(txtCity)
                            .add(txtCountry)
                            .add(txtStreet)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(79, 79, 79)
                                .add(fBtnSubmit)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(fFirstname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9)
                    .add(txtStreet, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(fLastname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel10)
                    .add(txtNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(fPostcode, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel11)
                    .add(txtCity, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(fInitialcredit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel12)
                    .add(txtCountry, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(fBtnSubmit)
                        .add(19, 19, 19)
                        .add(fLblNotifications)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(fBtnGetNotifications)
                        .add(14, 14, 14)))
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 167, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(fTabs, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 366, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fTxtMinAmountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fTxtMinAmountActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fTxtMinAmountActionPerformed

    private void fBtnGetNotificationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fBtnGetNotificationsActionPerformed
        getNotifications();
    }//GEN-LAST:event_fBtnGetNotificationsActionPerformed

    private void getNotifications() {
    	Vector<String> notifications = fCustomer.getNotifications();
        for (int i = 0; i < notifications.size(); i++) {
        	addNotification(notifications.get(i));
        }
    }
    
	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		System.setSecurityManager(new RMISecurityManager());

		/*
		 * Set the Nimbus look and feel
		 */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
		/*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException ex) {
			java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (InstantiationException ex) {
			java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (IllegalAccessException ex) {
			java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		} catch (javax.swing.UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(Gui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		//</editor-fold>

		/*
		 * Create and display the form
		 */
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				try {
					new Gui().setVisible(true);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JButton fBtnAddProduct;
    private javax.swing.JButton fBtnCredit;
    private javax.swing.JButton fBtnDebit;
    private javax.swing.JButton fBtnGetNotifications;
    private javax.swing.JButton fBtnPlace;
    private javax.swing.JButton fBtnSearch;
    private javax.swing.JButton fBtnSubmit;
    private javax.swing.JLabel fCaptchaImage;
    private javax.swing.JLabel fCaptchaLabel;
    private javax.swing.JTextField fFirstname;
    private javax.swing.JTextField fInitialcredit;
    private javax.swing.JButton fJoinAuction;
    private javax.swing.JTextField fLastname;
    private javax.swing.JLabel fLblBid;
    private javax.swing.JLabel fLblNameProductAdd;
    private javax.swing.JLabel fLblNameSearch;
    private javax.swing.JLabel fLblNotifications;
    private javax.swing.JTextField fPostcode;
    private javax.swing.JRadioButton fRbtnDutch;
    private javax.swing.JRadioButton fRbtnEnglish;
    private javax.swing.JRadioButton fRbtnVickrey;
    private javax.swing.JTabbedPane fTabs;
    private javax.swing.JTextField fTxtAddName;
    private javax.swing.JTextField fTxtBid;
    private javax.swing.JTextField fTxtCaptcha;
    private javax.swing.JTextField fTxtCredit;
    private javax.swing.JTextField fTxtDebit;
    private javax.swing.JTextField fTxtDuration;
    private javax.swing.JTextField fTxtJoinAuction;
    private javax.swing.JTextField fTxtMaxAmount;
    private javax.swing.JTextField fTxtMinAmount;
    private javax.swing.JTextField fTxtNameSearch;
    private javax.swing.JTextArea fTxtNotifications;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtCountry;
    private javax.swing.JTextField txtNumber;
    private javax.swing.JTextField txtStreet;
    // End of variables declaration//GEN-END:variables

	public void pushNotification(String notification) {
		addNotification(notification);
	}
}
